package conservare.modelo.banco;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import conservare.modelo.CpfCnpj;
import conservare.modelo.Endereco;

@Entity
@Table(name="TB_EMPRESA")
public class Empresa implements Serializable {

	private static final long serialVersionUID = -2434591776682307055L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="EMPRESA_ID")
	private Integer id;
	
	@Column(name="NOME_EMPRESA")
	private String nome;
	
	@Column(name="cpf_cnpj")
	private CpfCnpj cpfCnpj;
	
	
	@Embedded
	private Endereco endereco;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public CpfCnpj getCpfCnpj() {
		return cpfCnpj;
	}
	public void setCpfCnpj(CpfCnpj cpfCnpj) {
		this.cpfCnpj = cpfCnpj;
	}
	
	public String getCpfCnpjFormatado(){
		return getCpfCnpj().getCpfCnpjFormatado();
	}
	
	public Endereco getEndereco() {
		return endereco;
	}
	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}
	
	public String getEnderecoCompletoFormatadoParaUmaLinha(){
		return getEndereco().getEnderecoCompletoFormatadoParaUmaLinha();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Empresa other = (Empresa) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
